## Thanks to jsaffar@gmail.com
import zlib
import sys
import os.path

def crc(fileName):
 ##for the script to work on any sfv file no matter where it's located , we have to parse the absolute path of each file within sfv
 ##so, we will add the file path to each file name , pretty neat huh ?
 if os.path.exists(fileName):
  store=open(fileName, "rb")
  prev=0
  for eachLine in store:
   prev = zlib.crc32(eachLine, prev)
  store.close()
  return "%x"%(prev & 0xFFFFFFFF)

def get_files_to_transfer(sfv_file):
    release_folder=os.path.dirname(sfv_file)
    files_to_transfer = []
    if os.path.exists(sfv_file)==True:
     if sfv_file[-3:]=="sfv":
      s=open(sfv_file)
      names_list=[]
      sfv_list=[]
      ##loop thru all lines of sfv, removes all unnecessary /r /n chars, split each line to two values,creates two distinct arrays 
      for line in s.readlines():
       m=line.rstrip('\r\n')
       m=m.split(' ')
       names_list.append(m[0])
       sfv_list.append(m[1])
      i=0
      no_errors=False
      while(len(names_list)>i): 
       calc_sfv_value=crc(os.path.join(release_folder,names_list[i]))
       if sfv_list[i].lstrip('0')==calc_sfv_value:
        #print "MATCH"
        no_errors=True
       else:
        files_to_transfer.append(names_list[i])
        #print "this was a problem with file"
        no_errors=False
       i=i+1
    return files_to_transfer
